@using BlazorApp.Utils.Prometheus.Models.Interfaces
@inherits BlazorApp.Pages.Common.PageBase

@if (AllMetrics is { Count: > 0 })
{
    @if (AllMetrics.Any(x => x.Name == MetricName))
    {
        <GridRow Class="grid-table">
            <GridCol Span="16">@Title</GridCol>
            <GridCol Span="8">
                <NumberFormat Unit="@Unit" Number="@AllMetrics.FirstOrDefault(x => x.Name == MetricName)?.Measurements.Sum(x => x.Value)"></NumberFormat>
                @if (MultipleGroupBy is { Count: > 0 })
                {
                    <Button Type="@ButtonType.Link" OnClick=@(() => _showDetail = true)>@L["Detail"]</Button>
                }
            </GridCol>
        </GridRow>
        <Modal Closable="true" @bind-Visible="@_showDetail"
               Width="1000" Resizable=true
               Style="top: 20px"
               Title=@Title>
            @if (MultipleGroupBy is { Count: > 0 })
            {
                <MetricsCounterGaugeGroupByMultipleView AllMetrics="@AllMetrics"
                                                        MetricName="@MetricName"
                                                        Unit="@Unit"
                                                        MultipleGroupBy="@MultipleGroupBy">
                </MetricsCounterGaugeGroupByMultipleView>
            }
        </Modal>
    }
}

@code {

    [Parameter] public IList<IMetric> AllMetrics { get; set; }

    [Parameter] public string MetricName { get; set; }

    [Parameter] public string Title { get; set; }

    [Parameter] public string Unit { get; set; }

    [Parameter] public List<string> MultipleGroupBy { get; set; }
    private bool _showDetail = false;

}
